package com.kingint.web.admin.base.controller;


import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.admin.base.service.BasItemsLeftService;
import com.kingint.mbg.bas.entity.BasItemsLeft;


/**
 * @描述：遗留物品相关设置表控制类
 * @作者: wxh
 * @日期: 2020-12-22
 */
@RestController
@RequestMapping("/basItemsLeft")
@Api(value = "BasItemsLeftController", description = "遗留物品相关设置表")
@CrossOrigin
public class BasItemsLeftController {

    @Autowired
    public BasItemsLeftService basItemsLeftService;


    @ApiOperation(value = "添加遗留物品相关设置表")
    @PostMapping("/create")
    //@PreAuthorize("hasAuthority('basItemsLeft:create')")
    public Object create(@Validated(Insert.class) @RequestBody BasItemsLeft basItemsLeft) {
        int i = basItemsLeftService.insertItemsLeftInfo(basItemsLeft);
        if (i > 0) {
            return K.ok().data(basItemsLeft.getId());
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "更新遗留物品相关设置表")
    @PutMapping("/update")
    //@PreAuthorize("hasAuthority('basItemsLeft:update')")
    public Object update(@Validated(Update.class) @RequestBody BasItemsLeft basItemsLeft) {
        int i = basItemsLeftService.updateItemsLeftInfo(basItemsLeft);
        if (i > 0) {
            return K.ok().data(basItemsLeft.getId());
        } else {
            return K.error();
        }
    }


    @ApiOperation(value = "删除遗留物品相关设置表")
    @DeleteMapping("/delete/{id}")
    //@PreAuthorize("hasAuthority('basItemsLeft:delete')")
    public Object delete(@PathVariable("id") Integer id) {
        int i = basItemsLeftService.deleteItemsLeftInfo(id);
        if (i > 0) {
            return K.ok();
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据遗留物品相关设置表名称分页获取遗留物品相关设置表列表")
    @GetMapping("/list")
    //@PreAuthorize("hasAuthority('basItemsLeft:list')")
    public Object getList(BasItemsLeft basItemsLeft,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {

        return basItemsLeftService.getItemsLeftList(basItemsLeft, pageNum, pageSize);
    }

    @ApiOperation(value = "根据编号查询遗留物品相关设置表信息")
    @GetMapping("/{id}")
    // @PreAuthorize("hasAuthority('basItemsLeft:get')")
    public Object getItem(@PathVariable("id") Long id) {
        BasItemsLeft basItemsLeft = basItemsLeftService.getById(id);
        return K.ok().data(basItemsLeft);
    }
}